<template>
  <div>
    <!-- data对应数据 -->
    <!-- row-key 选择的依据 通过id选择 -->
    <!-- tree-props 属性数据的属性 -->
    <!-- default-expand-all 默认展开所有子集 -->
    <el-table
      :data="tableData"
      style="width: 100%; margin-bottom: 20px"
      row-key="id"
      border
      default-expand-all
      :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
    >
      <!-- sortable 排序 -->
      <el-table-column prop="id" label="ID" width="180">
      </el-table-column>
      <el-table-column prop="title" label="标题" width="180">
      </el-table-column>
      <el-table-column prop="type" label="类型">
        <template slot-scope="scope">
          <div>
              <el-tag type="success" v-if="scope.row.type==1">目录</el-tag>
              <el-tag type="danger" v-if="scope.row.type==2">菜单</el-tag>
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="icon" label="图标">
        <template slot-scope="scope">
          <i :class="scope.row.icon"></i>
        </template>
      </el-table-column>
      <el-table-column prop="url" label="地址"> </el-table-column>
      <el-table-column prop="status" label="状态">
        <template slot-scope="scope">
          <div>
              <el-tag type="success" v-if="scope.row.status==1">已启用</el-tag>
              <el-tag type="danger" v-if="scope.row.status==2">禁用</el-tag>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <div>
              <el-button type="primary" icon="el-icon-edit" circle @click="edit(scope.row)" size="mini"></el-button>
              <el-button type="danger" icon="el-icon-delete" circle size="mini" @click="del(scope.row.id)"></el-button>
          </div>
        </template>
      </el-table-column>
    </el-table>
     <!-- <el-button type="text" @click="open">点击打开 Message Box</el-button> -->
  </div>
</template>

<script>
import {menuListTree,menuDel} from '@/api.js'
export default {
  data() {
    return {
      tableData: [],
    };
  },
  created() {
    this.getMenu()
  },
  methods:{
    async getMenu(){
      let res=await menuListTree();
      this.tableData=res.list
    },
    edit(info){
      this.$emit('edit',info)
    },
    del(id){
      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(async() => {
          let res=await menuDel(id);
          if(res.code==200){
            this.tableData=res.list;
          }
          console.log(res);
          this.$message({
            type: 'success',
            message: '删除成功!'
          });
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });          
        });
    }
  }
};
</script>
<style scoped>
</style>